Skip to content

feat(ourlogs): Add a trace item details endpoint + tests - #86235

Merged
colin-sentry merged 5 commits into
masterfrom
trace_item_details
Mar 4, 2025
Merged

colin-sentry merged 5 commits into
masterfrom
trace_item_details

Conversation

@colin-sentry

@colin-sentry colin-sentry commented Mar 3, 2025 •

Copy link
Copy Markdown
Contributor

We want to be able to get all of the details for a specific trace-item, for example, a log or span.

This endpoint facilitates that - it was not merged with the existing event APIs because it has a different response schema.

Example request: http://localhost:7899/api/0/projects/sentry/python/trace-items/01955DB7E34B7412992D6E5CD3027FFB/?dataset=ourlogs

Example response:

{
            "attributes": {
                "bool_attr": {"valBool": true},
                "float_attr": {"valFloat": 3.0},
                "int_attr": {"valInt": "2"},
                "sentry.body": {"valStr": "foo"},
                "sentry.item_type": {"valInt": "3"},
                "sentry.organization_id": {"valInt": 1},
                "sentry.project_id": {"valInt": 1},
                "sentry.severity_number": {"valInt": "0"},
                "sentry.severity_text": {"valStr": "INFO"},
                "sentry.trace_id": {"valStr": "6d852644-d8c4-4d05-9ecc-7805193081bc"},
                "str_attr": {"valStr": "1"},
            },
            "itemId": "01955DB7E34B7412992D6E5CD3027FFB",
            "timestamp": "2025-03-03T21:07:12Z"
        }

@colin-sentry
colin-sentry requested a review from a team as a code owner March 3, 2025 21:19
@colin-sentry
colin-sentry requested a review from a team March 3, 2025 21:19
@colin-sentry
colin-sentry requested a review from a team as a code owner March 3, 2025 21:19
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 3, 2025
@colin-sentry
colin-sentry requested review from k-fish and wmak March 3, 2025 21:30
@codecov

codecov Bot commented Mar 3, 2025 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 94.66667% with 4 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...sentry/api/endpoints/project_trace_item_details.py 94.87% 2 Missing ⚠️
src/sentry/utils/snuba_rpc.py 77.77% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #86235       +/-   ##
===========================================
+ Coverage   46.68%   87.96%   +41.27%     
===========================================
  Files        9707     9728       +21     
  Lines      550543   551655     +1112     
  Branches    21483    21483               
===========================================
+ Hits       257043   485273   +228230     
+ Misses     293133    66015   -227118     
  Partials      367      367               

@wmak

wmak commented Mar 3, 2025

Copy link
Copy Markdown
Member

Can we remove the valBool, valFloat etc. from the response and just have the value directly?

@colin-sentry

Copy link
Copy Markdown
Contributor Author

Can we remove the valBool, valFloat etc. from the response and just have the value directly?

json doesn't support big integers - that's the big reason otel does it this way

@k-fish k-fish left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming you check all the ACL / features are correct, otherwise 👍

if dataset == "ourlogs":
trace_item_type = TRACE_ITEM_TYPE_LOG
else:
raise BadRequest(detail=f"Unknown dataset: '{dataset}'")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe test this branch (can do it later too not super important)

Comment on lines +50 to +51
end_timestamp_proto = ProtoTimestamp()
end_timestamp_proto.GetCurrentTime()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the timestamp is user submitted, we can't guarantee the window of GetCurrentTime is correct, but this should work for now.

"itemId": resp["itemId"],
"timestamp": resp["timestamp"],
"attributes": {
attr["name"]: convert_rpc_attribute_to_json(attr["value"])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏



@region_silo_endpoint
class ProjectTraceItemDetailsEndpoint(ProjectEndpoint):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this base class guarantee the project ACL?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup

@colin-sentry
colin-sentry merged commit af07727 into master Mar 4, 2025
@colin-sentry
colin-sentry deleted the trace_item_details branch March 4, 2025 18:43
k-fish added a commit that referenced this pull request Mar 4, 2025
### Summary
This adds the EventsTagTree like behaviour that queries and shows all
log details when opening a row. Once we figure out the rest of the EAP
items tables / detail views we can make a generic component.

Blocked on #86235 to replace the
mock data in the hook with an actual backend call.

#### Screenshots
![Screenshot 2025-03-03 at 5 16
46 PM](https://github.com/user-attachments/assets/7fa46ffb-2c62-46c2-9ff3-f33b9b59db79)
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 20, 2025

This branch was successfully deployed

1 active deployment
Preview — 8b2b3b80 Deployed Mar 4, 2025 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants